﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TKD14S : UIKDANSP
    {

        public TKD14S()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VKDANSP();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            Save();
            string _key = KEY;
            KEY = "";
            KEY = _key;//触发关联界面更改
            base.OnSave();
        }
        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 16)
                return;
            dwData = TBMain.NewRow();
            dwData["KDSMANDANT"] = app.Mandant;
            dwData["KDSKUNDNR"] = ORDERNUM.Substring(0, 8);
            dwData["KDSANSPNA"] = ORDERNUM.Substring(8, 8);
            SResult = ((VKDANSP)MV).QueryKDANSP(dwData, 2);
            MergeData(SResult, true);
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            ((VKDANSP)MV).DeleteKDANSP(dwMaster, 1);
            filter = "KDSKUNDNR='" + dwMaster["KDSKUNDNR"].ToString() + "' AND KDSANSPNA='" + dwMaster["KDSANSPNA"].ToString() + "'";

            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
    }
}
